package Power_Asisst.main;

import process.TCPClient;
import process.UDPClient;
import Power_Asisst.main.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class RemotePowerPoint extends Activity{
	
	private Button Open;
	private Button Home;
	private Button Next ;
	private Button Previous;
	private Button End;
	private Button Back;
	private String GiaoThuc ="";
	private String[] IP ;
	private Button Disconect;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.remotepowerpoint);
        Open = (Button)findViewById(R.id.btn_open);
        Home = (Button)findViewById(R.id.btn_Home);
        Next = (Button)findViewById(R.id.btn_next);
        Previous = (Button)findViewById(R.id.btn_previous);
        End = (Button)findViewById(R.id.btn_end);
        Back = (Button)findViewById(R.id.btn_back);
        Disconect = (Button)findViewById(R.id.btnDisconect);
        Bundle bundle = getIntent().getExtras();
        GiaoThuc = bundle.getString("Giao");
        // khue has mod here 
        IP = bundle.getStringArray("IP");
        // ---> end
		OnClickListener m_click = new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Button bt = (Button)v;
				String ThongTin = bt.getText().toString();
				/*UDPClient udp = new UDPClient();
				String ThongBao = udp.KetNoi(ThongTin);*/
				if(GiaoThuc.equals("UDP"))
				{
					//ThongTin += "\n";
					UDPClient udp = new UDPClient();
					String ThongBao = udp.KetNoi(ThongTin,IP);
				}
				else
				{
					TCPClient tcp = new TCPClient();
					String ThongBao  =tcp.KetNoi(ThongTin);
				}
				if(ThongTin.equals("Back"))
				{
					Intent intent = new Intent();
			    	intent.setClass(getBaseContext(),Power_AsisstActivity.class);
					
					startActivity(intent);
				}
				if(ThongTin.equals("Disconect"))
				{
					Intent intent = new Intent();
			    	intent.setClass(getBaseContext(),Power_AsisstActivity.class);
					
					startActivity(intent);
				}
			}
		};
		Open.setOnClickListener(m_click);
		Home.setOnClickListener(m_click);
		Next.setOnClickListener(m_click);
		Previous.setOnClickListener(m_click);
		End.setOnClickListener(m_click);
		Back.setOnClickListener(m_click);
		Disconect.setOnClickListener(m_click);
	}
	 @Override
	    public boolean onKeyDown(int keyCode, KeyEvent event)
	    { 
		 UDPClient udp = new UDPClient();
	    	String ThongTin ="";
	    	int s =0;
	    	super.onKeyDown(keyCode, event);
	    	
	    	boolean bool = false;
	    	if(keyCode==KeyEvent.KEYCODE_MENU) 
	    	{  
	    		s++;
	    		bool = true;
	    		ThongTin="End";
	    		bool = true;
				
				String ThongBao = udp.KetNoi(ThongTin,IP);
				return bool;
	    	}
	    	if(keyCode==KeyEvent.KEYCODE_BACK) 
	    	{  
	    		s++;
	    		bool = true;
	    		ThongTin="Home";
			//	UDPClient udp = new UDPClient();
				String ThongBao = udp.KetNoi(ThongTin,IP);
				return bool;
	    	}
	    	
	    	if(keyCode== KeyEvent.KEYCODE_HOME)
	    	{
	    		bool = true;
	    		ThongTin="Home";
				//UDPClient udp = new UDPClient();
				String ThongBao = udp.KetNoi(ThongTin,IP);
				return bool;

	    	}
	    	if(keyCode==KeyEvent.KEYCODE_VOLUME_UP)
	    	{
	    		
	    		ThongTin="Next";
	    		bool = true;
	    	//	UDPClient udp = new UDPClient();
				String ThongBao = udp.KetNoi(ThongTin,IP);
				return bool;
	    	}
	    	if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN)
	    	{
	    		bool = true;
	    		ThongTin="Previous";
			//	UDPClient udp = new UDPClient();
				String ThongBao = udp.KetNoi(ThongTin,IP);
				return bool;
	    	}
	    	
	    	return bool;
	    }
	

}
